package spec.zhangyuehua.$05;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
 * Created by yue on 2017/11/8.
 */
public class Example5_2 {
    public static void main(String[] args) {
        //定义集合
        Collection c=new ArrayList();
        //给集合添加元素
        c.add("stu1");
        c.add("stu2");
        c.add("stu3");
        //获取迭代器
        Iterator i1=c.iterator();       //ctrl+alt+b查看接口实现
        //Itr是iterator的实现
        while(i1.hasNext()){
            Object e=i1.next();
            System.out.println("i1="+e);
        }
        if(c.isEmpty()){
            System.out.println("c is Empty!");
        }
        else {
            System.out.println("c is not Empty!size="+c.size());
        }
        Iterator i2=c.iterator();
        while(i2.hasNext()){
            Object e=i2.next();
            System.out.println("remove="+e);
            i2.remove();
        }
        Iterator i3=c.iterator();
        if(!i3.hasNext()){
            System.out.println("没有元素了");
        }
        if(c.isEmpty()) {
            System.out.println("c is Empty!");
        }
    }
}
